<?php
$ip = $_GET['ip'];

$domain = 'http://www.webservicex.net';
$service = '/geoipservice.asmx/GetGeoIP';

$url = $domain.$service.'?IPAddress='.$ip;

if(strlen($ip)<7) echo "Please define an IP!";
$result=file_get_contents($url);

$GeoIP = new SimpleXMLElement($result);
$country = $GeoIP->CountryName[0];

//Build the response xml
header('Content-Type: text/xml');

$xml = '<?xml version="1.0" encoding="utf-8"?>';
$xml .= "<result>";
$xml .= "<countryname>" . $country . "</countryname>";
$xml .= "</result>";

echo $xml;
?>

